<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>

    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

    <style>
        body {
            background-color: gray;
        }
        .login-div {
            width: 400px;
            /* height: 200px; */
            margin: 0 auto;
            margin-top: 200px;
            border: 1px solid black;
            padding: 10px;
        }
    </style>
</head>
<body>
    <div class="login-div">
        <ul class="nav nav-tabs" role="tablist">
            <li class="active">
              <a href="#usernameLogin"   data-toggle="tab">用户名登录</a>
            </li>
            <li>
                <a href="#emailLogin" data-toggle="tab">邮箱验证码登录</a>
            </li>
        </ul>
      
        <!-- 用户名登录 -->
        <div class="tab-content">
          <div class="tab-pane active" id="usernameLogin">
            <form action="/login" method="POST">
                <div class="form-group">
                    <label>用户名</label>
                    <input type="text" class="form-control" placeholder="Username" name="username">
                </div>
                <div class="form-group">
                    <label>密码</label>
                    <input type="password" class="form-control"  placeholder="Password" name="password">
                </div>
            
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="rememberType"> 记住我
                    </label>
                </div>
                <button type="submit" class="btn btn-default">登录</button>
            </form>
          </div>
          <!-- 邮箱登录 -->
          <div class="tab-pane" id="emailLogin">            
            <form action="/email/login" method="POST">
                <div class="form-group" >
                    <label>邮箱地址</label>
                    <input type="email" class="form-control" placeholder="Email" name="email" id="email">
                </div>
                <div class="form-group">
                    <label>验证码</label>
                    <input type="text" class="form-control"  placeholder="Code" name="email_code">
                </div>
            
                <div class="form-group">
                    <label>
                        <button type="button" class="btn btn-default" id="getCode">获取验证码</button>
                        <span id="showCode" style="margin-left: 20px;"></span>
                    </label>
                </div>
                <button type="submit" class="btn btn-default">登录</button>
            </form>
          </div>
        </div>
    
    </div>

    <script>
        $('#nav a').on('click', function(e) {
            e.preventDefault();
            $(this).tab('show');
        }); 

        $('#getCode').on('click', function() {
            $.ajax({
                type: "GET",
                url: "/getEmailCode",
                data: {
                    email: $('#email').val()
                },
                // dataType: "dataType",
                success: function (response) {
                    $('#showCode').text(response);
                }
            });
        });
    </script>
</body>
</html>